import React, { Component } from 'react'
import {Redirect,Route,Switch} from 'react-router-dom'
import memoryUser from '../../utils/memoryUtils'
import { Layout } from 'antd';
import Header from '../../components/header'
import LeftNav from '../../components/left-nav'
import Home from '../home/home'
import Category from '../category/category'
import Product from '../product/product'
import Role from '../role/role'
import User from '../user/user'
import Bar from '../charts/bar'
import Line from '../charts/line'
import Pie from '../charts/pie'



const {Footer, Sider, Content } = Layout;

/**
 * 管理页面
 */
export default class Admin extends Component {
  render() {
    const user = memoryUser.user
    if (!user || !user._id) {
      // 没有user会自动跳转到登录页面===>login
      return <Redirect to='/login' />
    }
    return (
      <Layout style={{minHeight: '100vh',width: '100%'}}>
      <Sider>
        <LeftNav />
      </Sider>
      <Layout>
        <Header>Header</Header>
        <Content style={{margin: '20px',backgroundColor: 'white'}}>
          <Switch>
            <Route path='/home' component={Home} />
            <Route path='/category' component={Category} />
            <Route path='/product' component={Product} />
            <Route path='/role' component={Role} />
            <Route path='/user' component={User} />
            <Route path='/charts/bar' component={Bar} />
            <Route path='/charts/line' component={Line} />
            <Route path='/charts/pie' component={Pie} />
            <Redirect to='/home'></Redirect>
          </Switch>
        </Content>
        <Footer style={{color: '#999',textAlign: 'center'}}>React后台管理底部世界</Footer>
      </Layout>
    </Layout>
    )
  }
}
